import type { App } from 'vue';
import { createRouter, createWebHashHistory } from 'vue-router';
import { setupRouterGuard } from './guard';

const router = createRouter({
  history: createWebHashHistory(import.meta.env.BASE_URL), //hash路由方式
  routes: [
    {
      path: '/',
      name: 'index',
      component: () => import('../views/index.vue'),
      redirect: '/table',
      children: [
        {
          path: '/table',
          name: 'table',
          meta: {
            title: '我的表格',
            showSidebar: true,
          },
          component: () => import('../views/table/index.vue'),
        }
      ],
    },
    {
      path: '/404',
      name: '404',
      meta: {
        title: '404',
      },
      component: () => import('@/views/404.vue'),
      children: [],
    },
  ],
});

export function setupRouter(app: App<Element>) {
  setupRouterGuard(router);
  app.use(router);
}
